<?php

namespace App\Managers\Admin;

use App\Exceptions\AdminException;
use App\Managers\BaseManager;
use App\Models\WebPathModel;


class WebPathManager extends BaseManager
{
    public function __construct(WebPathModel $model)
    {
        parent::__construct();
        $this->model = $model;
    }

    public function _before_lists()
    {
        $this->model->getQueryByModel()->orderBy('id');
    }

    public function _before_save()
    {
        $path = $this->getData('path');
        $has_path = WebPathModel::where('path', $path)->first();
        if ($has_path) {
            throw new AdminException('该网站已存在');
        }
    }
}
